{include file="public/toper" /}
<div class="layui-tab layui-tab-brief main-tab-container">
    <ul class="layui-tab-title main-tab-title">
        <div class="main-tab-item">信息修改</div>
    </ul>
    <div class="layui-tab-content">
        <form class="layui-form">
            <div class="layui-tab-item layui-show">
                <input type="hidden" name="id" value="{$data.id}">

                <div class="layui-form-item">
                    <label class="layui-form-label">管理员账号</label>
                    <div class="layui-input-inline input-custom-width">
                        <input type="username" name="username" value="{$data.username}" lay-verify="username" autocomplete="off" placeholder="请输入管理员账号"  class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">管理员密码</label>
                    <div class="layui-input-inline input-custom-width">
                        <input type="password" name="password" value="" lay-verify="password" autocomplete="off" placeholder="请输入管理员密码"  class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit="" lay-filter="edit">立即提交</button>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript">
    layui.use(['form','element'],function(){
        var form = layui.form
            ,jq = layui.jquery;


        //自定义验证规则
        form.verify({
            username: function(value){
                if(value.length < 4){
                    return '用户名至少得4个字符啊';
                }
            }
            ,password: [/(.+){6,12}$/, '密码必须6到12位']
        });

        //监听提交
        form.on('submit(edit)', function (data) {
            loading = layer.load(2, {
                shade: [0.2, '#000'] //0.2透明度的白色背景
            });
            var param = data.field;
            jq.post(
                '{:url("editPost")}',
                param,
                function (data) {
                    if (data.code == 200) {
                        layer.close(loading);
                        layer.msg(data.msg, {icon: 1, time: 1000}, function () {
                            parent.location.reload();//do something

                        });
                    } else {
                        layer.close(loading);
                        layer.msg(data.msg, {icon: 2, anim: 6, time: 1000});
                    }
                }).error(function () {
                layer.close(loading);
                layer.msg('服务器错误', {icon: 2, anim: 6, time: 1000});
            });
            return false;
        });
    });
</script>
{include file="public/footer" /}